<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script src="./promise.js"></script>
<script>
  function fn (number) {
    console.log('number', number)
    function promiseFn(res,rej) {
      console.log('Promise')

      if (number > 10) {
        res('success')
      } else {
        rej('error')
      }
    }
    new Promise(function (res,rej) {
      // res(number)
      // setTimeout(function() {
        if(number < 10) {
          res(number)
        }else {
          rej('error')
        }
      //   // res(number)
      //   // rej('error')
      // }, 3000)
    }).then(res => {
      console.log('fn',res)
      return new Promise(promiseFn)
    }, rej => {
      console.log('fnRej', rej)
    }).then(res => {
      console.log('promiseFn res', res)
    }, rej => {
      console.log('promiseFn Rej', rej)
    })
  }
  // fn(9)
  Promise.resolve('success').then(e => console.log(e)).catch((e) => {
    console.error(`捕获错误catch+${e}`)
  }).finally(() => {
    console.log('successfinally')
  })
  Promise.reject('error').catch((e) => {
    console.error(`捕获错误catch+${e}`)
  }).finally(() => {
    console.log('errorfinally')
  })
</script>
